# Maintainer: Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
# Contributor: Andrea Scarpino <andrea@archlinux.org>

pkgname=libb64
pkgver=1.2.1
pkgrel=4
pkgdesc='Base64 Encoding/Decoding Routines'
url='http://libb64.sourceforge.net/'
depends=('glibc')
arch=('loong64' 'x86_64')
license=('custom:Public Domain')
source=("https://downloads.sourceforge.net/${pkgname}/${pkgname}-${pkgver}.zip"
        "https://sources.debian.net/data/main/libb/libb64/1.2-3/debian/patches/bufsiz-as-buffer-size.diff")
sha256sums=('20106f0ba95cfd9c35a13c71206643e3fb3e46512df3e2efb2fdbf87116314b2'
            '0a8a978e94a924b4f62795de251aa1a5ceb53a1024ea60193d7f3e5a5794fa20')

prepare() {
  cd $pkgname-$pkgver
  patch -p1 -i "$srcdir"/bufsiz-as-buffer-size.diff
}

build() {
  cd ${pkgname}-${pkgver}/src
  export CFLAGS="${CFLAGS} -fPIC"
  make

  export CFLAGS="${CFLAGS} -shared -Wl,-soname,${pkgname}.so.0"
  gcc ${LDFLAGS} ${CFLAGS} *.o -o ${pkgname}.so.0
}

package() {
  cd ${pkgname}-${pkgver}

  install -d "${pkgdir}/usr/lib"
  install src/libb64.so.0 "${pkgdir}/usr/lib"
  ln -sf /usr/lib/libb64.so.0 "${pkgdir}/usr/lib/libb64.so"

  cp -r include "${pkgdir}/usr"

  install -Dm644 LICENSE \
      "${pkgdir}"/usr/share/licenses/${pkgname}/LICENSE
}
